package ltd.xushen.sheep;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpRequest;
import java.util.HashMap;
import java.util.Map;

public class Sheep {

    public static String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTQ0MzcwMDMsIm5iZiI6MTY2MzMzNDgwMywiaWF0IjoxNjYzMzMzMDAzLCJqdGkiOiJDTTpjYXRfbWF0Y2g6bHQxMjM0NTYiLCJvcGVuX2lkIjoiIiwidWlkIjozMjkzNDA0NiwiZGVidWciOiIiLCJsYW5nIjoiIn0.X_Bnc1UrUOsi1y6jIaVmy3b8TXR34KlPGAkyHFYHyFE";

    //循环次数
    public static int count = 10;

    public static void main(String[] args) {
        try {

            System.out.println("1111111111");
            Console.log("羊了个羊开始启动");
            for (int i = 1; i <= count; i++) {
                int time = RandomUtil.randomInt(60, 6000);
                Console.log("生成随机完成时间:"+time);
                finish_game_naw(1, time,i);
                Thread.sleep(RandomUtil.randomInt(1000, 6000));
            }
            Console.log("羊了个羊结束任务");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void finish_game_naw(int state, int time,int flag){
        try {
            String finish_api = "https://cat-match.easygame2021.com/sheep/v1/game/game_over?rank_score=1&rank_state=%s&rank_time=%s&rank_role=1&skin=1";
            String url = String.format(finish_api, state, time);
            Map<String, String> headers = new HashMap<>(10);
            headers.put("Connection", "Keep-Alive");
            headers.put("Content-Type", "application/json");
            headers.put("Accept", "*/*");
            headers.put("Accept-Language", "en-us,en");
            headers.put("Host", "cat-match.easygame2021.com");
            headers.put("Referer", "https://servicewechat.com/wx141bfb9b73c970a9/14/index.html");
            headers.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 MicroMessenger/7.0.4.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF");
            headers.put("Xweb_xhr", "1");
            headers.put("T", token);
            String result = HttpRequest.get(url)
                    .addHeaders(headers)
                    .execute().body();
            Console.log("第" + flag + "次：" + result);
        } catch (Exception e) {
            Console.log("请求超时");
        }
    }
}
